<template>
  <div>
    <vxe_table
      :options="options"
      @handleTableBtn="handleTableBtn"
      ref="baseTable"
    >
      <template #btn>
        <el-button type="success" @click="add" v-permission="['btn_roleAdmin_add']">新建角色</el-button>
      </template>
    </vxe_table>
    <AddDialog ref="add" @success="success"></AddDialog>
    <AuthDialog ref="auth" @success="success"></AuthDialog>
  </div>
</template>

<script>
import vxe_table from "@/components/table/vxe_table.vue";
import tableMixin from "@/mixins";
import AddDialog from "./comps/addDialog.vue";
import AuthDialog from "./comps/authDialog.vue";
import { list,del } from "@/api/role";
import { hasBtnAuth, parseTime } from '@/utils';
export default {
  mixins: [tableMixin],
  components: {
    vxe_table,
    AddDialog,
    AuthDialog
  },
  data() {
    return {
      options: {
        id: "roletable",
        apiFn: list,
        columns: [
          { field: "roleId", title: "角色ID" },
          {
            field: "name",
            title: "角色名称",
            search: true,
            valueType: "input",
          },
          { field: "creator", title: "创建人ID" },
          {
            field: "createTime",
            title: "时间",
            type: "html",
            formatter: ({ row }) => parseTime(row.createTime)
          },
        ],
        btnWidth:300,
        btn: [
          {
            title: "编辑",
            handleName: "edit",
            type: "success",
            show:()=>hasBtnAuth('btn_roleAdmin_edit')
          },
          {
            title: "删除",
            handleName: "handleDel",
            type: "danger",
            show:()=>hasBtnAuth('btn_roleAdmin_del')

          },
          {
            title: "权限配置",
            handleName: "handleOpenAuth",
            show:()=>hasBtnAuth('btn_orgUserAdmin_set')

          },
        ],
      },
    };
  },
  methods: {
    handleOpenAuth(row){
      this.$refs.auth.open(row)
    },
    handleDel(row){
      this.$del({roleId:row.roleId},del)
    }
  },
};
</script>
